package view.listener;

import java.util.List;

import org.eclipse.swt.events.KeyEvent;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;

import controller.UseCaseController;
import controller.data.searchRevision.SearchRevisionRequest;
import controller.data.searchRevision.SearchRevisionResponse;
import singleton.Singleton;
import view.views.RevisionView;


public class KeyListener implements org.eclipse.swt.events.KeyListener {
	
	private IWorkbenchPartSite site;
	private RevisionView view;

	public KeyListener(IWorkbenchPartSite site, RevisionView revisionView){
		this.site = site;
		this.view = revisionView;
	}
	
	public void keyPressed(KeyEvent e) {
		if(e.keyCode == 13){
			Singleton singleton = Singleton.getInstance();
			UseCaseController useCaseControllerImplementation = singleton
					.getUseCaseController();
			Singleton.getInstance().setGetGoForIt(true);
			List<String> listOfTags = view.getListOfTags();
			SearchRevisionRequest request = new SearchRevisionRequest(
					listOfTags);
			List<SearchRevisionResponse> listOfRevisions = useCaseControllerImplementation
					.searchRevision(request);
			// + Arrays.toString(listOfRevisions.toArray()));
			singleton.setListOfRevisions(listOfRevisions);
			view.relaodRevision();
			// createViewOfRevisions();
			
			IViewPart view = site.getPage().findView(
			"plug_inv01.views.RevisionView");
			site.getPage().hideView(view);
			try {
				site.getPage().showView("plug_inv01.views.RevisionView");
			} catch (PartInitException event) {
				// TODO Auto-generated catch block
				event.printStackTrace();
			}
		}		
	}

	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
}
